/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nyrestaurantpaymentsystem;

import javax.swing.JLabel;
import javax.swing.JTextArea;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class Restaurant {
    private MoneyTimer moneytimer;
    private Table[] tableArray;
    private int numberOfTables;
    private String[] strArrayTableNames;
    private JTextArea[] jTextAreaArray;
    private NyRestaurantPaymentSystemView restaurantGUI;
    
    
    public Restaurant(NyRestaurantPaymentSystemView nyRestGUI, int tables, String[] strArray, JTextArea[] jta)
    {
        strArrayTableNames = strArray;
        numberOfTables = tables;
        tableArray = new Table[numberOfTables];
        moneytimer = new MoneyTimer(); 
        restaurantGUI = nyRestGUI;
        
        //assert(jTextAreaArray.length == strArrayTableNames.length);
                
        for(int i = 0; i < numberOfTables; i++)
        {
            tableArray[i] = new Table(this, jta[i]);
        }
    }
    
    public NyRestaurantPaymentSystemView getGUI()
    {
        return restaurantGUI;
    }
    
    public int getMoneySpent(int i)
    {
    return getTable(i).getMoneySpent();
    }

    public Table getTable(int i)
    {
        return tableArray[i];
    }
            
    public MoneyTimer getMoneyTimer()
    {
        return moneytimer;
    }
    
    private int getTableNumberOfTableName(String s)
    {
        for(int i = 0; i < numberOfTables; i++)
        {
            if(s.equals(strArrayTableNames[i]))
            {
                return i;
            }
            else
            {
                return -1;
            }
        }
        
        return -1;
    
    }
    
    public Table returnTableBelongsToJLabel(JLabel jLabel)
    {
        if(jLabel.getName().equals("table_1"))
        {
            return tableArray[0]; 
        }
        
        
        else if(jLabel.getName().equals("table_2"))
        {
            return tableArray[1]; 
        }
        
        
        else if(jLabel.getName().equals("table_3"))
        {
            return tableArray[2]; 
        }

        
        else if(jLabel.getName().equals("table_4"))
        {
            return tableArray[3]; 
        }
        
        return tableArray[3];
        //int num = getTableNumberOfTableName(jLabel.getName() );
        //return tableArray[num];
    }
    

}
